#include<iostream>
using namespace std;
#include<vector>
class Solution {
public:
    vector<vector<int>> ans;
    vector<int> path;
    void dfs(vector<vector<int>>& graph, int now) {
        if (now == graph.size() - 1)
        {
            ans.emplace_back(path);
            return;
        }
        for (auto& e : graph[now])
        {
            path.emplace_back(e);
            dfs(graph, e);
            path.pop_back();
        }
    }
    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
        path.emplace_back(0);
        dfs(graph, 0);
        return ans;
    }
};